"""System barcode printer."""
from __future__ import with_statement
import threading
import random
import genshi
from string import letters
from turbogears import expose, controllers
from mnemoply import model
from mnemoply.controllers import Report

class BarcodePrinter(controllers.Controller):
    def __init__(self):
        controllers.Controller.__init__(self)

    @expose(template="genshi:mnemoply.templates.barcode")
    def index(self, **kw):
        return {}

    @expose()
    def print_all(self, **kw):
        ids = [
            e.id for e in model.Environment.select()
            if e.name.startswith("admin_type") and e.name != "admin_type_collection"
        ]
        return Report.generate('BarcodePrint', ids=",".join([str(i) for i in ids]))

exposed = BarcodePrinter()
